import 'package:gold/generated/json/base/json_convert_content.dart';
import 'package:gold/model/user_model.dart';

UserModel $UserModelFromJson(Map<String, dynamic> json) {
  final UserModel userModel = UserModel();
  final int? uid = jsonConvert.convert<int>(json['uid']);
  if (uid != null) {
    userModel.uid = uid;
  }
  final String? nickname = jsonConvert.convert<String>(json['nickname']);
  if (nickname != null) {
    userModel.nickname = nickname;
  }
  final String? avatar = jsonConvert.convert<String>(json['avatar']);
  if (avatar != null) {
    userModel.avatar = avatar;
  }
  final String? sex = jsonConvert.convert<String>(json['sex']);
  if (sex != null) {
    userModel.sex = sex;
  }
  final int? birthday = jsonConvert.convert<int>(json['birthday']);
  if (birthday != null) {
    userModel.birthday = birthday;
  }
  final int? role = jsonConvert.convert<int>(json['role']);
  if (role != null) {
    userModel.role = role;
  }
  final int? points = jsonConvert.convert<int>(json['points']);
  if (points != null) {
    userModel.points = points;
  }
  final double? amount = jsonConvert.convert<double>(json['amount']);
  if (amount != null) {
    userModel.amount = amount;
  }
  final String? lockedAmount = jsonConvert.convert<String>(json['locked_amount']);
  if (lockedAmount != null) {
    userModel.lockedAmount = lockedAmount;
  }
  final String? invCode = jsonConvert.convert<String>(json['inv_code']);
  if (invCode != null) {
    userModel.invCode = invCode;
  }
  final String? createdAt = jsonConvert.convert<String>(json['created_at']);
  if (createdAt != null) {
    userModel.createdAt = createdAt;
  }
  final String? updatedAt = jsonConvert.convert<String>(json['updated_at']);
  if (updatedAt != null) {
    userModel.updatedAt = updatedAt;
  }
  final String? deletedAt = jsonConvert.convert<String>(json['deleted_at']);
  if (deletedAt != null) {
    userModel.deletedAt = deletedAt;
  }
  final UserInfo? user = jsonConvert.convert<UserInfo>(json['user']);
  if (user != null) {
    userModel.user = user;
  }
  return userModel;
}

Map<String, dynamic> $UserModelToJson(UserModel entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['uid'] = entity.uid;
  data['nickname'] = entity.nickname;
  data['avatar'] = entity.avatar;
  data['sex'] = entity.sex;
  data['birthday'] = entity.birthday;
  data['role'] = entity.role;
  data['points'] = entity.points;
  data['amount'] = entity.amount;
  data['locked_amount'] = entity.lockedAmount;
  data['inv_code'] = entity.invCode;
  data['created_at'] = entity.createdAt;
  data['updated_at'] = entity.updatedAt;
  data['deleted_at'] = entity.deletedAt;
  data['user'] = entity.user?.toJson();
  return data;
}

extension UserModelExtension on UserModel {
  UserModel copyWith({
    int? uid,
    String? nickname,
    String? avatar,
    String? sex,
    int? birthday,
    int? role,
    int? points,
    double? amount,
    String? lockedAmount,
    String? invCode,
    String? createdAt,
    String? updatedAt,
    String? deletedAt,
    UserInfo? user,
  }) {
    return UserModel()
      ..uid = uid ?? this.uid
      ..nickname = nickname ?? this.nickname
      ..avatar = avatar ?? this.avatar
      ..sex = sex ?? this.sex
      ..birthday = birthday ?? this.birthday
      ..role = role ?? this.role
      ..points = points ?? this.points
      ..amount = amount ?? this.amount
      ..lockedAmount = lockedAmount ?? this.lockedAmount
      ..invCode = invCode ?? this.invCode
      ..createdAt = createdAt ?? this.createdAt
      ..updatedAt = updatedAt ?? this.updatedAt
      ..deletedAt = deletedAt ?? this.deletedAt
      ..user = user ?? this.user;
  }
}

UserInfo $UserInfoFromJson(Map<String, dynamic> json) {
  final UserInfo userInfo = UserInfo();
  final int? uid = jsonConvert.convert<int>(json['uid']);
  if (uid != null) {
    userInfo.uid = uid;
  }
  final int? mobile = jsonConvert.convert<int>(json['mobile']);
  if (mobile != null) {
    userInfo.mobile = mobile;
  }
  return userInfo;
}

Map<String, dynamic> $UserInfoToJson(UserInfo entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['uid'] = entity.uid;
  data['mobile'] = entity.mobile;
  return data;
}

extension UserInfoExtension on UserInfo {
  UserInfo copyWith({
    int? uid,
    int? mobile,
  }) {
    return UserInfo()
      ..uid = uid ?? this.uid
      ..mobile = mobile ?? this.mobile;
  }
}